package com.yeyks.service.impl;

import com.yeyks.dal.dao.SmsHistoryMapper;
import com.yeyks.dal.domain.SmsHistory;
import com.yeyks.dal.domain.UserInfo;
import com.yeyks.service.SmsHistoryService;
import com.yeyks.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author fuchangshuai
 * @date 2019/3/27 2:34 PM
 */
@Slf4j
@Service
public class SmsHistoryServiceImpl implements SmsHistoryService {
    @Autowired
    private SmsHistoryMapper smsHistoryDAO;
    @Autowired
    private UserInfoService userInfoService;

    public Integer insertSelective(SmsHistory smsHistory) {
        return smsHistoryDAO.insertSelective(smsHistory);
    }

    public Integer insertByPhoneDesc(String phone, String desc, String code) {
        UserInfo userInfo = userInfoService.selectUseInfoPhone(phone);
        if (userInfo == null) {
            log.info("通过手机号获取不到该用户{}", phone);
        }
        SmsHistory smsHistory = new SmsHistory();
        smsHistory.setContents(code);
        smsHistory.setPhone(phone);
        smsHistory.setSmsType(desc);
        if (userInfo != null) {
            smsHistory.setAccountId(userInfo.getId().longValue());
        }
        return smsHistoryDAO.insertSelective(smsHistory);
    }

}
